package com.bra.ui.adapter;

import java.util.List;

import com.bra.R;
import com.bra.bean.CommentBean;
import com.bra.bean.ArticleBean;
import com.bra.view.ImagerLoaderHelper;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
/**
 * 评论adapter
 * @author lenovo
 *
 */
public class Comment_adapter extends BaseAdapter {
	private Context context;
	private List<CommentBean> comments;
	private ImageLoader imageLoader;
	private ImagerLoaderHelper imageLoaderHelper;

	public Comment_adapter(Context context,List<CommentBean> comments) {
		this.context = context;
		this.comments = comments;
		imageLoader = ImageLoader.getInstance();
		imageLoaderHelper = ImagerLoaderHelper.getInstance();
	}

	public void addData(List<CommentBean> comments) {
		// TODO Auto-generated method stub
		this.comments.addAll(comments);
	}

	public void setData(List<CommentBean> comments) {
		this.comments = comments;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return comments.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return comments.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = View.inflate(context,
					R.layout.comment_item, null);
			holder = new ViewHolder();
			holder.cgxq_pinglun_time = (TextView) convertView
					.findViewById(R.id.cgxq_pinglun_time);
			holder.pl_user_name = (TextView) convertView
					.findViewById(R.id.pl_user_name);
			holder.pl_user_content = (TextView) convertView
					.findViewById(R.id.pl_user_content);
			holder.pl_user_image = (ImageView) convertView
					.findViewById(R.id.pl_user_image);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.cgxq_pinglun_time.setText(comments.get(position).getCreateDate());
		holder.pl_user_name.setText(comments.get(position).getUsername());	
		holder.pl_user_content.setText(comments.get(position).getContent());
		imageLoader.displayImage(comments.get(position).getImgSrc(),
				holder.pl_user_image, imageLoaderHelper.getOptions());
		return convertView;
	}

	public class ViewHolder {
		public ImageView pl_user_image;
		private TextView cgxq_pinglun_time, pl_user_name, pl_user_content;
	}

}
